
package saxon.gui.model.xml;

import javax.xml.transform.TransformerException;
import net.sf.saxon.s9api.SaxonApiException;
import org.xml.sax.SAXParseException;

/**
 *
 * @author mlenart
 */
public class XException extends Exception {
	
	public XException(SaxonApiException ex) {
		super(getMsgFrom(ex));
	}
	
	private static String getMsgFrom(SaxonApiException ex) {
		if (ex.getCause() instanceof TransformerException && ex.getCause().getCause() instanceof SAXParseException) {
			SAXParseException saxEx = (SAXParseException) ex.getCause().getCause();
			return String.format(
					"Error on line %d column %d of %s: %s", 
					saxEx.getLineNumber(), 
					saxEx.getColumnNumber(), 
					saxEx.getSystemId(),
					saxEx.getMessage());
		}
		else {
			return ex.getMessage();
		}
	}
}
